package com.haoniu.deal.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.haoniu.common.core.utils.bean.BeanUtils;
import com.haoniu.deal.domain.TransactionTurnoverSearchRequestDto;
import com.haoniu.deal.domain.TransactionTurnoverSearchResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoniu.common.log.annotation.Log;
import com.haoniu.common.log.enums.BusinessType;
import com.haoniu.common.security.annotation.RequiresPermissions;
import com.haoniu.deal.domain.TCwPayOrder;
import com.haoniu.deal.service.ITCwPayOrderService;
import com.haoniu.common.core.web.controller.BaseController;
import com.haoniu.common.core.web.domain.AjaxResult;
import com.haoniu.common.core.utils.poi.ExcelUtil;
import com.haoniu.common.core.web.page.TableDataInfo;
import org.springframework.web.servlet.ModelAndView;

/**
 * 交易流水（支付流水信息）Controller
 * 
 * @author haoniu
 * @date 2022-07-23
 */
@RestController
@RequestMapping("/deal")
public class TCwPayOrderController extends BaseController
{
    @Autowired
    private ITCwPayOrderService tCwPayOrderService;

    // 1.查询方法
    @RequiresPermissions("deals:deal:list")
    @GetMapping("/list")
    public TableDataInfo searchTradingFlow(TransactionTurnoverSearchRequestDto param){

        startPage();

        //创建查询条件
        TransactionTurnoverSearchRequestDto params =new TransactionTurnoverSearchRequestDto();

        //具有相同属性的bean 转换方便
        BeanUtils.copyProperties(param, params);

        //判断查询条件
        if(param.getTradeAccountType()==-1){
            params.setTradeAccountType(0);
        }
        if(param.getUserType()==-1){
            params.setUserType(0);
        }
        if(param.getTradeResult()==-1){
            params.setTradeResult(0);
        }
        if(param.getPayWay()==-1){
            params.setPayWay(0);
        }

        List<TransactionTurnoverSearchResponseDto> list = tCwPayOrderService.getList(param);

        System.err.println(list);

        return getDataTable(list);

    }


    /**
     * 查询交易流水（支付流水信息）列表
     */
//    @RequiresPermissions("deals:deal:list")
//    @GetMapping("/list")
//    public TableDataInfo list(TCwPayOrder tCwPayOrder)
//    {
//        startPage();
//        List<TCwPayOrder> list = tCwPayOrderService.selectTCwPayOrderList(tCwPayOrder);
//        return getDataTable(list);
//    }

    /**
     * 导出交易流水（支付流水信息）列表
     */
    @RequiresPermissions("deals:deal:export")
    @Log(title = "交易流水（支付流水信息）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCwPayOrder tCwPayOrder)
    {
        List<TCwPayOrder> list = tCwPayOrderService.selectTCwPayOrderList(tCwPayOrder);
        ExcelUtil<TCwPayOrder> util = new ExcelUtil<TCwPayOrder>(TCwPayOrder.class);
        util.exportExcel(response, list, "交易流水（支付流水信息）数据");
    }

    /**
     * 获取交易流水（支付流水信息）详细信息
     */
    @RequiresPermissions("deals:deal:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tCwPayOrderService.selectTCwPayOrderById(id));
    }

    /**
     * 新增交易流水（支付流水信息）
     */
    @RequiresPermissions("deals:deal:add")
    @Log(title = "交易流水（支付流水信息）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCwPayOrder tCwPayOrder)
    {
        return toAjax(tCwPayOrderService.insertTCwPayOrder(tCwPayOrder));
    }

    /**
     * 修改交易流水（支付流水信息）
     */
    @RequiresPermissions("deals:deal:edit")
    @Log(title = "交易流水（支付流水信息）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCwPayOrder tCwPayOrder)
    {
        return toAjax(tCwPayOrderService.updateTCwPayOrder(tCwPayOrder));
    }

    /**
     * 删除交易流水（支付流水信息）
     */
    @RequiresPermissions("deals:deal:remove")
    @Log(title = "交易流水（支付流水信息）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCwPayOrderService.deleteTCwPayOrderByIds(ids));
    }
}
